package demo.bytebuddy.example1;

import lombok.extern.log4j.Log4j;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.dynamic.loading.ClassReloadingStrategy;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers;

/**
 * description: <br>
 * createTime: 2021/1/6 14:23 <br>
 *
 * @author zzh
 */
public class Main {

    public static void main(String[] args) {
        Log.log("log");
        ByteBuddyAgent.install();
        new ByteBuddy().redefine(Log.class)
                .method(ElementMatchers.named("log"))
                .intercept(MethodDelegation.to(Log4j.class))
                .make()
                .load(Thread.currentThread().getContextClassLoader(), ClassReloadingStrategy.fromInstalledAgent());

        Log.log("log");
    }
}
